package com.youhp.spire.xls.demo.PivotTable;

import com.spire.xls.*;
import com.spire.xls.core.spreadsheet.pivottables.*;

public class FormatDataField {
    public static void main(String[] args) {
        //Create a workbook and load an Excel file from disk.
        Workbook workbook = new Workbook();
        workbook.loadFromFile("data/FormatDataField.xlsx");

        //Get the first worksheet.
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Access the PivotTable.
        XlsPivotTable pt = null;
        if (sheet.getPivotTables().get(0)instanceof XlsPivotTable){
           pt = (XlsPivotTable) sheet.getPivotTables().get(0);
        }

        //Access the data field.
        PivotDataField pivotDataField = pt.getDataFields().get(0);

        //Set data display format.
        pivotDataField.setShowDataAs(PivotFieldFormatType.PercentageOfColumn);

        //Save to file.
        workbook.saveToFile("output/FormatDataField.xlsx", ExcelVersion.Version2013);
   }
}
